package com.lenovo.manufacture.Activity;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.lenovo.manufacture.R;
import com.lenovo.manufacture.fragment.Cheliangdingzhi;
import com.lenovo.manufacture.fragment.Dingdanguanli;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

public class CheLiangDingZhiActivity extends AppCompatActivity {

    private ArrayList<Fragment> list;
    private ViewPager vp_che_liang_ding_zhi;
    private TextView tv_che_title;
    private TextView tv_che_ding;
    private TextView tv_ding_dan;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_che_liang_ding_zhi);
        initView();
        list = new ArrayList<>();
        list.add(new Cheliangdingzhi());
        list.add(new Dingdanguanli());

        tv_che_ding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vp_che_liang_ding_zhi.setCurrentItem(0);
            }
        });

        tv_ding_dan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               vp_che_liang_ding_zhi.setCurrentItem(1);
            }
        });

        vp_che_liang_ding_zhi.setAdapter(new ViewPage(getSupportFragmentManager()));
        vp_che_liang_ding_zhi.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    tv_che_title.setText("车辆定制");
                    tv_che_ding.setBackgroundResource(R.drawable.che_liang_select);
                    tv_ding_dan.setBackgroundResource(R.drawable.che_liang_noselect);
                } else if (position == 1) {
                    tv_che_title.setText("订单管理");
                    tv_che_ding.setBackgroundResource(R.drawable.che_liang_noselect);
                    tv_ding_dan.setBackgroundResource(R.drawable.che_liang_select);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    private void initView() {
        vp_che_liang_ding_zhi = (ViewPager) findViewById(R.id.vp_che_liang_ding_zhi);
        tv_che_title = (TextView) findViewById(R.id.tv_che_title);
        tv_che_ding = (TextView) findViewById(R.id.tv_che_ding);
        tv_ding_dan = (TextView) findViewById(R.id.tv_ding_dan);
    }


    class ViewPage extends FragmentStatePagerAdapter {


        public ViewPage(@NonNull FragmentManager fm) {
            super(fm);
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }
    }
}
